home *** CD-ROM | disk | FTP | other *** search
- #include "stdtypes.h"
- #include "stddebug.h"
-
- #include "client.h"
- #include "datagram.h"
- #include "platform.h"
- #include "reggie.h"
- #include "socket.h"
-
- #include "main.h"
-
- // Globals
- Str255 gInfo = "\pHello World!";
- DialogPtr gChooserDialogPtr;
- Boolean gQuitting;
- ListHandle gServiceList;
- ListHandle gURLList;
- short gFilterValue;
-
- // * *******************************************************************************
- // * *******************************************************************************
-
- void main(void) {
- OSErr err = noErr;
-
- Initialize();
- SetUpMenus();
- if(SetUpChooser())
- while(!gQuitting)
- err = EventLoop();
- DisposDialog(gChooserDialogPtr);
- }
-
- // * *******************************************************************************
- // * *******************************************************************************
-
- OSErr SetUpMenus(void) {
- InsertMenu(GetMenu(128), 0);
- AddResMenu(GetMHandle(128), 'DRVR');
-
- InsertMenu(GetMenu(129), 0);
- InsertMenu(GetMenu(130), 0);
-
- DisableItem(GetMenu(130), 1);
- DisableItem(GetMenu(130), 2);
- DisableItem(GetMenu(130), 3);
- DisableItem(GetMenu(130), 4);
-
- DrawMenuBar();
- }
-
- // * *******************************************************************************
- // * *******************************************************************************
-
- DialogPtr SetUpChooser(void) {
- Rect ServiceRect, URLRect, InfoRect, ServiceListBounds, URLListBounds;
- short iType, i=0, j=-1, row, total=0;
- Handle iHandle, aServiceIcon;
- Point serviceCellSize, URLCellSize;
- Ptr cellData;
- StringHandle iconString;
- Cell currentCell;
- OSErr err=noErr;
- GrafPtr oldPort;
-
- GetPort(&oldPort);
-
- if(gChooserDialogPtr = GetNewDialog(128, NULL, (WindowPtr)-1)) {
- SetPort(gChooserDialogPtr);
-
- GetDItem(gChooserDialogPtr, kServiceList, &iType, &iHandle, &ServiceRect);
- GetDItem(gChooserDialogPtr, kURLList, &iType, &iHandle, &URLRect);
-
- SetRect(&ServiceListBounds, 0, 0, 3, 3);
- SetPt(&serviceCellSize, 60, 60);
- gServiceList = LNew(&ServiceRect, &ServiceListBounds, serviceCellSize, 130, gChooserDialogPtr,
- TRUE, FALSE, FALSE, TRUE);
-
- SetRect(&URLListBounds, 0, 0, 1, 10);
- SetPt(&URLCellSize, 0, 0);
- gURLList = LNew(&URLRect, &URLListBounds, URLCellSize, 0, gChooserDialogPtr,
- TRUE, FALSE, FALSE, TRUE);
-
-
- cellData = NewPtr(sizeof(char)*64);
- if(MemError())
- return(0);
- i=128;
- total = Count1Resources('STR ');
- for(i=0; (i*3)+j<total; i++, j=0) {
- for(j=0; (j<3) && ((i*3)+j<total);j++) {
- GetIconSuite(&aServiceIcon, (i*3)+j+128, svAllAvailableData);
-
- iconString = GetString((i*3)+j+128);
- if(!iconString)
- break;
-
- SetPt((Point *)(¤tCell), j, i);
- BlockMove(&aServiceIcon, cellData, sizeof(Handle));
- BlockMove((*iconString)+1, cellData+sizeof(Handle), (*iconString)[0]);
- LSetCell(cellData, (*iconString)[0]+sizeof(Handle), currentCell, gServiceList);
-
- ReleaseResource((Handle)iconString);
- if(ResError())
- return(0);
- }
- }
- ShowWindow((WindowPtr)gChooserDialogPtr);
- SetPort(oldPort);
- }
-
- DisposePtr(cellData);
- return(gChooserDialogPtr);
- }
-
- // * *******************************************************************************
- // * *******************************************************************************
-
- //Initialize the ToolBox
- void Initialize(void) {
- WindowPtr mainPtr;
- OSErr error;
- SysEnvRec theWorld;
-
- gQuitting = FALSE;
-
- error = SysEnvirons(1, &theWorld);
- if (theWorld.hasColorQD == false) {
- SysBeep(50);
- ExitToShell(); /* If no color QD, we must leave. */
- }
-
- /* Initialize all the needed managers. */
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- MoreMasters();
- MoreMasters();
- MoreMasters();
- }
-
-
- // * *******************************************************************************
- // * *******************************************************************************
-
- void ChangeURLList(void) {
- qThrowIfError(QueryTracker(0x12345678, 0, 100, NULL, NULL, NULL,
- "sils.umich.edu"), 0);
- qThrowIfError(DumpRegEntries(), 0);
- }
-
- // * *******************************************************************************
- // * *******************************************************************************
-
- void DoMouseInDialog(EventRecord theEvent, short theItem) {
- GrafPtr oldPort;
- Handle filterPopUp;
- short iType;
- Rect iRect;
- RgnHandle infoRgn = NewRgn();
- Point localPt;
-
- GetPort(&oldPort);
- SetPort((GrafPtr)gChooserDialogPtr);
-
- localPt = theEvent.where;
- GlobalToLocal(&localPt);
- switch(theItem) {
- case kServiceList:
- case kServiceListScroll:
- LClick(localPt, theEvent.modifiers, gServiceList);
- ChangeURLList();
- break;
- case kURLList:
- case kURLListScroll:
- LClick(localPt, theEvent.modifiers, gURLList);
- break;
- case kFilterMenu:
- GetDItem(gChooserDialogPtr, kFilterMenu, &iType, &filterPopUp, &iRect);
- gFilterValue = GetCtlValue((ControlHandle)filterPopUp);
- GetDItem(gChooserDialogPtr, kInfoField, &iType, &filterPopUp, &iRect);
- RectRgn(infoRgn, &iRect);
- InvalRgn(infoRgn);
- default:
- break;
- }
-
- DisposeRgn(infoRgn);
- SetPort(oldPort);
- }
-
- // * *******************************************************************************
- // * *******************************************************************************
-
- void DoMouseOutsideDialog(EventRecord theEvent, short theItem) {
- short winPart;
- GrafPtr oldPort;
- long menuStuff;
- WindowPtr testWindow;
-
- GetPort(&oldPort);
- SetPort((GrafPtr)gChooserDialogPtr);
-
- winPart = FindWindow(theEvent.where, &testWindow);
-
- switch(winPart) {
- case inMenuBar:
- menuStuff = MenuSelect(theEvent.where);
- if(menuStuff)
- DoMenu(HiWord(menuStuff), LoWord(menuStuff));
- break;
- case inDrag:
- DragWindow((WindowPtr)gChooserDialogPtr, theEvent.where, &(qd.screenBits.bounds));
- break;
- case inGoAway:
- if(TrackGoAway(gChooserDialogPtr, theEvent.where))
- gQuitting = TRUE;
- break;
- default:
- break;
- }
- SetPort(oldPort);
- }
-
- // * *******************************************************************************
- // * *******************************************************************************
-
- void DoKey(EventRecord theEvent, short theItem) {
- GrafPtr oldPort;
-
- GetPort(&oldPort);
- SetPort((GrafPtr)gChooserDialogPtr);
-
-
- //Do Stuff...
-
-
- SetPort(oldPort);
- }
-
- // * *******************************************************************************
- // * *******************************************************************************
-
- void DoMenu(short menuID, short menuItem) {
- GrafPtr oldPort;
- Str255 DAName;
-
- GetPort(&oldPort);
- SetPort((GrafPtr)gChooserDialogPtr);
-
- if((menuID == 0) && (menuItem < 0)) {
- GetItem(GetMHandle(128), menuItem, DAName);
- OpenDeskAcc(DAName);
- }
-
- if(menuID == 129) { //File Menu...
- gQuitting = TRUE;
- }
-
- if(menuID == 130) { //Edit Menu...
- //Everything is disabled...
- }
-
- HiliteMenu(0);
-
- SetPort(oldPort);
- }
-
- // * *******************************************************************************
- // * *******************************************************************************
-
- OSErr EventLoop(void) {
- DialogPtr myDlg;
- short theItem;
- EventRecord theEvent;
- Boolean handled = FALSE, inDialog = TRUE;
- long menuStuff;
- GrafPtr oldPort;
-
- if(WaitNextEvent(everyEvent, &theEvent, 30, NULL)) {
- GetPort(&oldPort);
- SetPort(gChooserDialogPtr);
- TextFont(0);
- TextSize(0);
- SetPort(oldPort);
- if ((theEvent.what != updateEvt) && (inDialog=IsDialogEvent(&theEvent)))
- handled = !DialogSelect(&theEvent, &myDlg, &theItem);
- GetPort(&oldPort);
- SetPort(gChooserDialogPtr);
- TextFont(1);
- TextSize(9);
- SetPort(oldPort);
-
- if(handled == FALSE) {
- switch(theEvent.what) {
- case mouseDown:
- if(inDialog)
- DoMouseInDialog(theEvent, theItem);
- else
- DoMouseOutsideDialog(theEvent, theItem);
- break;
- case keyDown:
- DoKey(theEvent, theItem);
- break;
- case updateEvt:
- DoUpdate();
- break;
- case nullEvent:
- default:
- break;
- }
- }
- else {
- if((theEvent.modifiers & cmdKey)&&(theEvent.what == keyDown))
- menuStuff = MenuKey(theEvent.message & charCodeMask);
- if(menuStuff) {
- HiliteMenu(HiWord(menuStuff));
- DoMenu(HiWord(menuStuff), LoWord(menuStuff));
- }
- }
- }
- return noErr;
- }
-
- // * *******************************************************************************
- // * *******************************************************************************
-
- void DoUpdate(void) {
- GrafPtr oldPort;
- Rect ServiceRect, URLRect, InfoRect;
- short iType;
- Handle iHandle;
-
- GetPort(&oldPort);
- SetPort(gChooserDialogPtr);
-
- GetDItem(gChooserDialogPtr, kServiceList, &iType, &iHandle, &ServiceRect);
- GetDItem(gChooserDialogPtr, kURLList, &iType, &iHandle, &URLRect);
- GetDItem(gChooserDialogPtr, kInfoField, &iType, &iHandle, &InfoRect);
-
- BeginUpdate(gChooserDialogPtr);
-
- UpdtDialog(gChooserDialogPtr, gChooserDialogPtr->visRgn);
-
- InsetRect(&ServiceRect, -1, -1);
- InsetRect(&URLRect, -1, -1);
-
- FrameRect(&ServiceRect);
- FrameRect(&URLRect);
-
- PenPat(&qd.gray);
- FrameRect(&InfoRect);
- PenPat(&qd.black);
-
- LUpdate((*gServiceList)->port->visRgn, gServiceList);
- LUpdate((*gURLList)->port->visRgn, gURLList);
-
- InsetRect(&InfoRect, 2, 2);
-
- NumToString(gFilterValue, gInfo);
- TextBox(&(gInfo[1]), gInfo[0], &InfoRect, 0);
-
- EndUpdate(gChooserDialogPtr);
-
- SetPort(oldPort);
- }
-